#313- Add in-memory template caching to speed up PDF processing#314
Open
Cubix33 wants to merge 1 commit intofireform-core:mainfrom
Open
#313- Add in-memory template caching to speed up PDF processing#314Cubix33 wants to merge 1 commit intofireform-core:mainfrom
Cubix33 wants to merge 1 commit intofireform-core:mainfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #313
📝 What does this PR do?
This PR significantly speeds up the PDF generation process by preventing the system from re-reading the same blank PDF form from the hard drive multiple times.
Instead of reading the template from scratch for every single request, the system now saves the raw PDF layout into the server's memory (RAM) the first time it sees it. Any future requests for that same form are loaded instantly from memory, making batch processing and repeated forms lightning fast!
🛠️ Changes Made
src/filler.py): Created aself._template_cachedictionary inside theFillerclass to store the raw bytes of the PDF files.src/filler.py): Updated thefill_formfunction. If a form is new, it reads it from the disk and caches it. If it's already in the cache, it bypasses the disk entirely and loads instantly usingPdfReader(fdata=...).src/main.py): Temporarily added a "double run" at the bottom ofmain.pyto easily demonstrate the cache working in real-time.✅ How to Test
make execorpython src/main.py).[LOG] Template Cache Miss...(It reads the file from disk).[LOG] Template Cache Hit!(It successfully bypasses the disk and uses the fast memory).EXAMPLE SCREENSHOT: